home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / awt / Component$FlipBufferStrategy.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  3.0 KB  |  153 lines

  1. package java.awt;
  2.  
  3. import java.awt.image.BufferStrategy;
  4. import java.awt.image.VolatileImage;
  5.  
  6. public class Component$FlipBufferStrategy extends BufferStrategy {
  7.    protected int numBuffers;
  8.    protected BufferCapabilities caps;
  9.    protected Image drawBuffer;
  10.    protected VolatileImage drawVBuffer;
  11.    protected boolean validatedContents;
  12.    int width;
  13.    int height;
  14.    // $FF: synthetic field
  15.    final Component this$0;
  16.  
  17.    protected Component$FlipBufferStrategy(Component var1, int var2, BufferCapabilities var3) throws AWTException {
  18.       this.this$0 = var1;
  19.       if (!(var1 instanceof Window) && !(var1 instanceof Canvas)) {
  20.          throw new ClassCastException("Component must be a Canvas or Window");
  21.       } else {
  22.          this.numBuffers = var2;
  23.          this.caps = var3;
  24.          this.createBuffers(var2, var3);
  25.       }
  26.    }
  27.  
  28.    protected void createBuffers(int var1, BufferCapabilities var2) throws AWTException {
  29.       if (var1 < 2) {
  30.          throw new IllegalArgumentException("Number of buffers cannot be less than two");
  31.       } else if (this.this$0.peer == null) {
  32.          throw new IllegalStateException("Component must have a valid peer");
  33.       } else if (var2 != null && var2.isPageFlipping()) {
  34.          this.width = this.this$0.getWidth();
  35.          this.height = this.this$0.getHeight();
  36.          if (this.drawBuffer == null) {
  37.             this.this$0.peer.createBuffers(var1, var2);
  38.          } else {
  39.             this.drawBuffer = null;
  40.             this.drawVBuffer = null;
  41.             this.destroyBuffers();
  42.             this.this$0.peer.createBuffers(var1, var2);
  43.          }
  44.  
  45.          this.updateInternalBuffers();
  46.       } else {
  47.          throw new IllegalArgumentException("Page flipping capabilities must be specified");
  48.       }
  49.    }
  50.  
  51.    private void updateInternalBuffers() {
  52.       this.drawBuffer = this.getBackBuffer();
  53.       if (this.drawBuffer instanceof VolatileImage) {
  54.          this.drawVBuffer = (VolatileImage)this.drawBuffer;
  55.       } else {
  56.          this.drawVBuffer = null;
  57.       }
  58.  
  59.    }
  60.  
  61.    protected Image getBackBuffer() {
  62.       if (this.this$0.peer != null) {
  63.          return this.this$0.peer.getBackBuffer();
  64.       } else {
  65.          throw new IllegalStateException("Component must have a valid peer");
  66.       }
  67.    }
  68.  
  69.    protected void flip(BufferCapabilities.FlipContents var1) {
  70.       if (this.this$0.peer != null) {
  71.          this.this$0.peer.flip(var1);
  72.       } else {
  73.          throw new IllegalStateException("Component must have a valid peer");
  74.       }
  75.    }
  76.  
  77.    protected void destroyBuffers() {
  78.       if (this.this$0.peer != null) {
  79.          this.this$0.peer.destroyBuffers();
  80.       } else {
  81.          throw new IllegalStateException("Component must have a valid peer");
  82.       }
  83.    }
  84.  
  85.    public BufferCapabilities getCapabilities() {
  86.       return this.caps;
  87.    }
  88.  
  89.    public Graphics getDrawGraphics() {
  90.       this.revalidate();
  91.       return this.drawBuffer.getGraphics();
  92.    }
  93.  
  94.    protected void revalidate() {
  95.       this.revalidate(true);
  96.    }
  97.  
  98.    void revalidate(boolean var1) {
  99.       this.validatedContents = false;
  100.       if (var1 && (this.this$0.getWidth() != this.width || this.this$0.getHeight() != this.height)) {
  101.          try {
  102.             this.createBuffers(this.numBuffers, this.caps);
  103.          } catch (AWTException var6) {
  104.          }
  105.  
  106.          this.validatedContents = true;
  107.       }
  108.  
  109.       this.updateInternalBuffers();
  110.       if (this.drawVBuffer != null) {
  111.          GraphicsConfiguration var2 = this.this$0.getGraphicsConfiguration_NoClientCode();
  112.          int var3 = this.drawVBuffer.validate(var2);
  113.          if (var3 == 2) {
  114.             try {
  115.                this.createBuffers(this.numBuffers, this.caps);
  116.             } catch (AWTException var5) {
  117.             }
  118.  
  119.             if (this.drawVBuffer != null) {
  120.                this.drawVBuffer.validate(var2);
  121.             }
  122.  
  123.             this.validatedContents = true;
  124.          } else if (var3 == 1) {
  125.             this.validatedContents = true;
  126.          }
  127.       }
  128.  
  129.    }
  130.  
  131.    public boolean contentsLost() {
  132.       return this.drawVBuffer == null ? false : this.drawVBuffer.contentsLost();
  133.    }
  134.  
  135.    public boolean contentsRestored() {
  136.       return this.validatedContents;
  137.    }
  138.  
  139.    public void show() {
  140.       this.flip(this.caps.getFlipContents());
  141.    }
  142.  
  143.    public void dispose() {
  144.       if (this.this$0.bufferStrategy == this) {
  145.          this.this$0.bufferStrategy = null;
  146.          if (this.this$0.peer != null) {
  147.             this.destroyBuffers();
  148.          }
  149.       }
  150.  
  151.    }
  152. }
  153.